package vdc.controller;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import vdc.view.MainForm;

public class MainConsoleController
{
	private static volatile MainConsoleController	instance;

	public static MainConsoleController getInstance()
	{
		if (MainConsoleController.instance == null)
		{
			synchronized (MainConsoleController.class)
			{
				if (MainConsoleController.instance == null)
				{
					MainConsoleController.instance = new MainConsoleController();
				}

			}
		}
		if (MainConsoleController.instance.form != null)
		{
			MainConsoleController.instance.form.repaint();
		}
		return MainConsoleController.instance;
	}

	private JPanel		contentPanel;

	private MainForm	form;

	private MainConsoleController()
	{
		this.form = new MainForm();
		this.contentPanel = new JPanel();
		this.contentPanel.setBackground(Color.black);
		LineBorder border = new LineBorder(Color.BLUE, 2);
		this.form.getRootPane().setBorder(border);

		this.form.setContentPane(this.contentPanel);
		this.form.setVisible(true);

	}

	public void addLabel(String text)
	{
		int h = 10;
		Component[] cmpts = this.form.getComponents();
		if (cmpts != null)
		{
			h = cmpts[cmpts.length - 1].getY()
					+ cmpts[cmpts.length - 1].getHeight();
		}

		JLabel label = new JLabel(text);
		// label.setLocation(20, h);
		label.setOpaque(true);
		this.contentPanel.add(label);
		this.form.repaint();

	}

	public JPanel getContentPanel()
	{
		return this.contentPanel;
	}

	public MainForm getForm()
	{
		return this.form;
	}
}
